﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EzDesk.Core.Model;

namespace EzDesk.Core.CoreImpl
{
    public class CoreAppService : ICoreAppService
    {
        //todo: 在这个地方对应用程序的Core服务调用进行安全验证

        private ICoreService _coreService;

        public CoreAppService(ICoreService coreService)
        {
            this._coreService = coreService;
        }

        //todo: 使用DI重构
        public CoreAppService()
            : this(new CoreService())
        {}



        public UserProfile GetUserProfileByUserName(string userName)
        {
            return _coreService.GetUserProfileByUserName(userName);
        }

        public UserProfile GetUserProfileById(Guid userId)
        {
            return _coreService.GetUserProfileById(userId);
        }

        public void ChangeUserDept(Guid userId, Guid deptId)
        {
            _coreService.ChangeUserDept(userId, deptId);
        }

        public void ChangeUserReportId(Guid userId, Guid reportId)
        {
            _coreService.ChangeUserReportId(userId, reportId);
        }

        public void ChangeUserPosition(Guid userId, Guid positionId)
        {
            _coreService.ChangeUserPosition(userId, positionId);
        }

        public UserProfile CreateEmptyUserProfile(string userName)
        {
            return _coreService.CreateEmptyUserProfile(userName);
        }

        public IList<SimpleUser> GetSimpleUserInfos(string userIdStrs)
        {
            return _coreService.GetSimpleUserInfos(userIdStrs);
        }

        public IList<Dept> GetAllDepts()
        {
            return _coreService.GetAllDepts();
        }


        public SimpleUser GetSimpleUserInfoByUserName(string userName)
        {
            return _coreService.GetSimpleUserInfoByUserName(userName);
        }

        public IList<SimpleUser> GetAllUsersByMemberString(string memberString)
        {
            return _coreService.GetAllUsersByMemberString(memberString);
        }
        public IDictionary<Guid, string> GetChildrenByMemberString(string memberString)
        {
            return _coreService.GetChildrenByMemberString(memberString);
        }



        public IList<Group> GetAllSystemGroups()
        {
            return _coreService.GetAllSystemGroups();
        }


        public void UpdateFeedData(Guid feedId, string newFeedData)
        {
            _coreService.UpdateFeedData(feedId, newFeedData);
        }

        public void SetFeedIsAvailable(Guid feedId, string memberString, bool isAvailable)
        {
            _coreService.SetFeedIsAvailable(feedId, memberString, isAvailable);
        }


        public SimpleUser GetSimpleUserById(Guid userId)
        {
            return _coreService.GetSimpleUserById(userId);
        }


        public void SetFeedsIsAvailable(string feedIdStrs, string memberString, bool isAvailable)
        {
            _coreService.SetFeedIsAvailable(feedIdStrs, memberString, isAvailable);
        }

        public Group GetGroupById(Guid groupId)
        {
            return _coreService.GetGroupById(groupId);
        }

        public IList<Group> GetGroups(string groupIdStrs)
        {
            return _coreService.GetGroups(groupIdStrs);
        }


        public Group GetGroupMemberstring(string memberstring)
        {
            return _coreService.GetGroupMemberstring(memberstring);
        }


        public void UpdateFeedsData(string updateFeeds, string updateFeedData)
        {
            _coreService.UpdateFeedData(updateFeeds, updateFeedData);
        }



        public Guid SendFeed(string feedTypeStr, Guid templateId, Guid? senderId, string feedData, string memberString, bool sendToSelf)
        {
            return _coreService.SendFeed(
                feedTypeStr, templateId, senderId, feedData, memberString, 
                DateTime.Now.AddDays(10), /* todo: 根据feed类型等参数来研究有效期的问题 */
                sendToSelf
                );
        }


        public void UpdatePersonalFeedData(Guid feedId, string memberstring, string feedDataEx)
        {
            _coreService.UpdatePersonalFeedData(feedId, memberstring, feedDataEx);
        }

        #region ICoreAppService Members


        public Guid SendFeed(string feedTypeStr, string templateName, Guid? senderId, string feedData, string memberString, DateTime expireOn, bool sendToSelf)
        {
            return _coreService.SendFeed(feedTypeStr, templateName, senderId, feedData, memberString, expireOn, sendToSelf);
        }

        #endregion
    }
}
